home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-26  |  39.2 KB  |  1,387 lines

  1. /* Lisp object printing and output streams.
  2.    Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994
  3.    Free Software Foundation, Inc.
  4.    Copyright (C) 1994, 1995 Amdahl Corporation.
  5.  
  6. This file is part of XEmacs.
  7.  
  8. XEmacs is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with XEmacs; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. /* Synched up with: Not synched with FSF. */
  23.  
  24. /* This file has been Mule-ized. */
  25.  
  26. /* Seriously hacked on by Ben Wing for Mule. */
  27.  
  28. #include <config.h>
  29. #include "lisp.h"
  30.  
  31. #ifndef standalone
  32. #include "buffer.h"
  33. #include "bytecode.h"
  34. #include "extents.h"
  35. #include "frame.h"
  36. #include "emacsfns.h"
  37. #include "insdel.h"
  38. #include "lstream.h"
  39.  
  40. #endif /* not standalone */
  41.  
  42. Lisp_Object Vstandard_output, Qstandard_output;
  43.  
  44. /* The subroutine object for external-debugging-output is kept here
  45.    for the convenience of the debugger.  */
  46. Lisp_Object Qexternal_debugging_output;
  47. Lisp_Object Qalternate_debugging_output;
  48.  
  49. /* Avoid actual stack overflow in print.  */
  50. static int print_depth;
  51.  
  52. /* Maximum length of list or vector to print in full; noninteger means
  53.    effectively infinity */
  54.  
  55. Lisp_Object Vprint_length;
  56. Lisp_Object Qprint_length;
  57.  
  58. /* Maximum length of string to print in full; noninteger means
  59.    effectively infinity */
  60.  
  61. Lisp_Object Vprint_string_length;
  62. Lisp_Object Qprint_string_length;
  63.  
  64. /* Maximum depth of list to print in full; noninteger means
  65.    effectively infinity.  */
  66.  
  67. Lisp_Object Vprint_level;
  68.  
  69. /* Label to use when making echo-area messages. */
  70.  
  71. Lisp_Object Vprint_message_label;
  72.  
  73. /* Nonzero means print newlines in strings as \n.  */
  74.  
  75. int print_escape_newlines;
  76. int print_readably;
  77. int print_gensym;
  78.  
  79. Lisp_Object Qprint_escape_newlines;
  80. Lisp_Object Qprint_readably;
  81.  
  82. /* Force immediate output of all printed data.  Used for debugging. */
  83. int print_unbuffered;
  84.  
  85. FILE *termscript;    /* Stdio stream being used for copy of all output.  */
  86.  
  87.  
  88.  
  89. int stdout_needs_newline;
  90.  
  91. /* Write a string (in internal format) to stdio stream STREAM. */
  92.    
  93. void
  94. write_string_to_stdio_stream (FILE *stream, CONST Bufbyte *str,
  95.                   Bytecount offset, Bytecount len)
  96. {
  97.   int extlen;
  98.   char *extptr = charptr_to_external (str + offset, len, &extlen);
  99.   fwrite (extptr, 1, extlen, stream);
  100.   if (stream == stdout || stream == stderr)
  101.     {
  102.       if (termscript)
  103.     {
  104.       fwrite (extptr, 1, extlen, termscript);
  105.       fflush (termscript);
  106.     }
  107.       stdout_needs_newline = (extptr[extlen - 1] != '\n');
  108.     }
  109. }
  110.  
  111. /* Write a string to the output location specified in FUNCTION.
  112.    Arguments NONRELOC, RELOC, OFFSET, and LEN are as in
  113.    buffer_insert_string_1() in insdel.c. */
  114.  
  115. static void
  116. output_string (Lisp_Object function, CONST Bufbyte *nonreloc,
  117.            Lisp_Object reloc, Bytecount offset, Bytecount len)
  118. {
  119.   /* This function can GC */
  120.   Charcount ccoff, cclen;
  121.   /* We change the value of nonreloc (fetching it from reloc as
  122.      necessary), but we don't want to pass this changed value on to
  123.      other functions that take both a nonreloc and a reloc, or things
  124.      may get confused and an assertion failure in
  125.      fixup_internal_substring() may get triggered. */
  126.   CONST Bufbyte *newnonreloc = nonreloc;
  127.   struct gcpro gcpro1, gcpro2;
  128.  
  129.   /* Emacs won't print whilst GCing, but an external debugger might */
  130.   if (gc_in_progress) return;
  131.  
  132.   /* Perhaps not necessary but probably safer. */
  133.   GCPRO2 (function, reloc);
  134.  
  135.   fixup_internal_substring (newnonreloc, reloc, offset, &len);
  136.  
  137.   if (STRINGP (reloc))
  138.     newnonreloc = string_data (XSTRING (reloc));
  139.  
  140.   ccoff = bytecount_to_charcount (newnonreloc, offset);
  141.   cclen = bytecount_to_charcount (newnonreloc + offset, len);
  142.  
  143.   if (LSTREAMP (function))
  144.     {
  145.       /* Lstream_write() could easily cause GC inside of it, if the
  146.      stream is a print-stream. (It will call output_string()
  147.      recursively.) This is probably the fastest way to fix this
  148.      problem. (alloca() is very fast on machines that have it
  149.      built-in, and you avoid some nasty problems with recursion
  150.      that could result from using a static buffer somewhere.)
  151.  
  152.      The other possibility is to inhibit GC, but that of course
  153.      would require an unwind-protect, which is usually a lot
  154.      slower than the small amount of memcpy()ing that happens
  155.      here. */
  156.       if (STRINGP (reloc))
  157.     {
  158.       Bufbyte *copied = (Bufbyte *) alloca (len);
  159.       memcpy (copied, newnonreloc + offset, len);
  160.       Lstream_write (XLSTREAM (function), copied, len);
  161.     }
  162.       else
  163.     Lstream_write (XLSTREAM (function), newnonreloc + offset, len);
  164.  
  165.       if (print_unbuffered)
  166.     Lstream_flush (XLSTREAM (function));
  167.     }
  168.  
  169. #ifndef standalone
  170.   else if (BUFFERP (function))
  171.     {
  172.       CHECK_LIVE_BUFFER (function, 0);
  173.       buffer_insert_string (XBUFFER (function), nonreloc, reloc, offset, len);
  174.     }
  175.   else if (MARKERP (function))
  176.     {
  177.       /* marker_position will err if marker doesn't point anywhere */
  178.       Bufpos spoint = marker_position (function);
  179.  
  180.       buffer_insert_string_1 (XBUFFER (Fmarker_buffer (function)),
  181.                   spoint, nonreloc, reloc, offset, len,
  182.                   0);
  183.       Fset_marker (function, make_number (spoint + cclen), Qnil);
  184.     }
  185.   else if (FRAMEP (function))
  186.     {
  187.       struct frame *f = XFRAME (function);
  188.       if (!EQ (Vprint_message_label, echo_area_status (f)))
  189.     clear_echo_area_from_print (f, Qnil, 1);
  190.       echo_area_append (f, nonreloc, reloc, offset, len, Vprint_message_label);
  191.     }
  192. #endif /* not standalone */
  193.   else if (EQ (function, Qt) || EQ (function, Qnil))
  194.     {
  195.       write_string_to_stdio_stream (stdout, newnonreloc, offset, len);
  196.     }
  197.   else
  198.     {
  199.       Charcount iii;
  200.  
  201.       for (iii = ccoff; iii < cclen + ccoff; iii++)
  202.     {
  203.       call1 (function,
  204.          make_number (charptr_char (newnonreloc, iii)));
  205.       if (STRINGP (reloc))
  206.         newnonreloc = string_data (XSTRING (reloc));
  207.     }
  208.     }
  209.  
  210.   UNGCPRO;
  211. }
  212.  
  213. struct print_stream
  214. {
  215.   FILE *file;
  216.   Lisp_Object fun;
  217. };
  218.  
  219. #define get_print_stream(stream) \
  220.   ((struct print_stream *) Lstream_data (stream))
  221.  
  222. static int print_stream_writer (Lstream *stream, CONST unsigned char *data,
  223.                 int size);
  224. static Lisp_Object print_stream_marker (Lisp_Object obj,
  225.                     void (*markobj) (Lisp_Object));
  226.  
  227. DEFINE_LSTREAM_IMPLEMENTATION ("print", lstream_print, 0,
  228.                    print_stream_writer, 0, 0, print_stream_marker,
  229.                    sizeof (struct print_stream));
  230.  
  231. static Lstream *
  232. make_print_stream (FILE *file, Lisp_Object fun)
  233. {
  234.   Lstream *str = Lstream_new (lstream_print);
  235.   struct print_stream *ps = get_print_stream (str);
  236.  
  237.   ps->file = file;
  238.   ps->fun = fun;
  239.   return str;
  240. }
  241.  
  242. /* #### This isn't being used anywhere at the moment.  Is it supposed
  243.    to be? */
  244. #if 0
  245. static void
  246. reset_print_stream (Lstream *str, FILE *file, Lisp_Object fun)
  247. {
  248.   struct print_stream *ps = get_print_stream (str);
  249.  
  250.   Lstream_reopen (str);
  251.   ps->file = file;
  252.   ps->fun = fun;
  253. }
  254. #endif
  255.  
  256. static Lisp_Object
  257. print_stream_marker (Lisp_Object obj, void (*markobj) (Lisp_Object))
  258. {
  259.   return get_print_stream (XLSTREAM (obj))->fun;
  260. }
  261.  
  262. static int
  263. print_stream_writer (Lstream *stream, CONST unsigned char *data, int size)
  264. {
  265.   struct print_stream *ps = get_print_stream (stream);
  266.   if (ps->file)
  267.     {
  268.       write_string_to_stdio_stream (ps->file, data, 0, size);
  269.       /* Make sure it really gets written now. */
  270.       if (print_unbuffered)
  271.     fflush (ps->file);
  272.     }
  273.   else
  274.     output_string (ps->fun, data, Qnil, 0, size);
  275.   return size;
  276. }
  277.  
  278.  
  279. static Lisp_Object
  280. canonicalise_printcharfun (Lisp_Object printcharfun)
  281. {
  282.   if (NILP (printcharfun))
  283.     printcharfun = Vstandard_output;
  284.  
  285.   if (EQ (printcharfun, Qt) || NILP (printcharfun))
  286.     {
  287. #ifndef standalone
  288.       printcharfun = Fselected_frame (Qnil); /* print to minibuffer */
  289. #endif
  290.     }
  291.   return (printcharfun);
  292. }
  293.  
  294.  
  295. static Lisp_Object
  296. print_prepare (Lisp_Object printcharfun)
  297. {
  298.   Lisp_Object xstream = Qnil;
  299.   Lstream *s;
  300.   FILE *stdio_stream = 0;
  301.  
  302.   /* Emacs won't print whilst GCing, but an external debugger might */
  303.   if (gc_in_progress)
  304.     return (Qnil);
  305.  
  306.   printcharfun = canonicalise_printcharfun (printcharfun);
  307.   if (EQ (printcharfun, Qnil))
  308.     {
  309.       stdio_stream = stdout;
  310.     }
  311. #if 0 /* Don't bother */
  312.   else if (SUBRP (indirect_function (printcharfun, 0))
  313.            && (XSUBR (indirect_function (printcharfun, 0)) 
  314.                == Sexternal_debugging_output))
  315.     {
  316.       stdio_stream = stderr;
  317.     }
  318. #endif
  319.   
  320.   s = make_print_stream (stdio_stream, printcharfun);
  321.   XSETLSTREAM (xstream, s);
  322.   return (xstream);
  323. }
  324.  
  325. static void
  326. print_finish (Lisp_Object stream)
  327. {
  328.   /* Emacs won't print whilst GCing, but an external debugger might */
  329.   if (gc_in_progress)
  330.     return;
  331.  
  332.   Lstream_close (XLSTREAM (stream));
  333. }
  334.  
  335. #if 1 /* Prefer space over "speed" */
  336. #define write_char_internal(string_of_length_1, stream) \
  337.   write_string_1 ((Bufbyte *) (string_of_length_1), 1, (stream))
  338. #else
  339. #define write_char_internal(string_of_length_1, stream) \
  340.   output_string ((stream), (Bufbyte *) (string_of_length_1), Qnil, 0, 1)
  341. #endif
  342.  
  343. /* NOTE:  Do not call this with the data of a Lisp_String,
  344.  *  as printcharfun might cause a GC, which might cause
  345.  *  the string's data to be relocated.
  346.  *  Use print_object_internal (string, printcharfun, 0)
  347.  *  to princ a Lisp_String
  348.  * Note: "stream" should be the result of "canonicalise_printcharfun"
  349.  *  (ie Qnil means stdout, not Vstandard_output, etc)
  350.  */
  351. void
  352. write_string_1 (CONST Bufbyte *str, Bytecount size, Lisp_Object stream)
  353. {
  354.   /* This function can GC */
  355.   assert (size >= 0);
  356.   output_string (stream, str, Qnil, 0, size);
  357. }
  358.  
  359. void
  360. write_c_string (CONST char *str, Lisp_Object stream)
  361. {
  362.   /* This function can GC */
  363.   write_string_1 ((Bufbyte *) str, strlen (str), stream);
  364. }
  365.  
  366.  
  367. DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
  368.   "Output character CH to stream STREAM.\n\
  369. STREAM defaults to the value of `standard-output' (which see).")
  370.   (ch, stream)
  371.      Lisp_Object ch, stream;
  372. {
  373.   /* This function can GC */
  374.   Bufbyte str[MAX_EMCHAR_LEN];
  375.   Bytecount len;
  376.  
  377.   CHECK_COERCE_CHAR (ch, 0);
  378.   len = emchar_to_charptr (XINT (ch), str);
  379.   output_string (canonicalise_printcharfun (stream), str, Qnil, 0, len);
  380.   return ch;
  381. }
  382.  
  383. #ifndef standalone
  384.  
  385. void
  386. temp_output_buffer_setup (CONST char *bufname)
  387. {
  388.   /* This function can GC */
  389.   struct buffer *old = current_buffer;
  390.   Lisp_Object buf;
  391.  
  392. #ifdef I18N3
  393.   /* #### This function should accept a Lisp_Object instead of a char *,
  394.      so that proper translation on the buffer name can occur. */
  395. #endif
  396.  
  397.   Fset_buffer (Fget_buffer_create (build_string (bufname)));
  398.  
  399.   current_buffer->read_only = Qnil;
  400.   Ferase_buffer (Fcurrent_buffer ());
  401.  
  402.   XSETBUFFER (buf, current_buffer);
  403.   specbind (Qstandard_output, buf);
  404.  
  405.   set_buffer_internal (old);
  406. }
  407.  
  408. Lisp_Object
  409. internal_with_output_to_temp_buffer (CONST char *bufname, 
  410.                                      Lisp_Object (*function) (Lisp_Object arg),
  411.                                      Lisp_Object arg, 
  412.                                      Lisp_Object same_frame)
  413. {
  414.   int speccount = specpdl_depth ();
  415.   struct gcpro gcpro1, gcpro2, gcpro3;
  416.   Lisp_Object buf = Qnil;
  417.  
  418.   GCPRO3 (buf, arg, same_frame);
  419.  
  420.   temp_output_buffer_setup (GETTEXT (bufname));
  421.   buf = Vstandard_output;
  422.  
  423.   arg = (*function) (arg);
  424.  
  425.   temp_output_buffer_show (buf, same_frame);
  426.   UNGCPRO;
  427.  
  428.   return unbind_to (speccount, arg);
  429. }
  430.  
  431. DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, Swith_output_to_temp_buffer,
  432.        1, UNEVALLED, 0,
  433.   "Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.\n\
  434. The buffer is cleared out initially, and marked as unmodified when done.\n\
  435. All output done by BODY is inserted in that buffer by default.\n\
  436. The buffer is displayed in another window, but not selected.\n\
  437. The value of the last form in BODY is returned.\n\
  438. If BODY does not finish normally, the buffer BUFNAME is not displayed.\n\n\
  439. If variable `temp-buffer-show-function' is non-nil, call it at the end\n\
  440. to get the buffer displayed.  It gets one argument, the buffer to display.")
  441.   (args)
  442.      Lisp_Object args;
  443. {
  444.   /* This function can GC */
  445.   struct gcpro gcpro1;
  446.   Lisp_Object name;
  447.   int speccount = specpdl_depth ();
  448.   Lisp_Object buf, val;
  449.  
  450. #ifdef I18N3
  451.   /* #### should set the buffer to be translating.  See print_internal(). */
  452. #endif
  453.  
  454.   GCPRO1 (args);
  455.   name = Feval (Fcar (args));
  456.   UNGCPRO;
  457.  
  458.   CHECK_STRING (name, 0);
  459.   temp_output_buffer_setup ((char *) string_data (XSTRING (name)));
  460.   buf = Vstandard_output;
  461.  
  462.   val = Fprogn (Fcdr (args));
  463.  
  464.   temp_output_buffer_show (buf, Qnil);
  465.  
  466.   return unbind_to (speccount, val);
  467. }
  468. #endif /* not standalone */
  469.  
  470. DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0,
  471.   "Output a newline to STREAM.\n\
  472. If STREAM is omitted or nil, the value of `standard-output' is used.")
  473.   (stream)
  474.      Lisp_Object stream;
  475. {
  476.   /* This function can GC */
  477.   Bufbyte str[1];
  478.   str[0] = '\n';
  479.   output_string (canonicalise_printcharfun (stream), str, Qnil, 0, 1);
  480.   return Qt;
  481. }
  482.  
  483. DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0,
  484.   "Output the printed representation of OBJECT, any Lisp object.\n\
  485. Quoting characters are printed when needed to make output that `read'\n\
  486. can handle, whenever this is possible.\n\
  487. Output stream is STREAM, or value of `standard-output' (which see).")
  488.   (object, stream)
  489.      Lisp_Object object, stream;
  490. {
  491.   /* This function can GC */
  492.   Lisp_Object the_stream = Qnil;
  493.   struct gcpro gcpro1, gcpro2, gcpro3;
  494.  
  495.   GCPRO3 (object, stream, the_stream);
  496.   print_depth = 0;
  497.   the_stream = print_prepare (stream);
  498.   print_internal (object, the_stream, 1);
  499.   print_finish (the_stream);
  500.   UNGCPRO;
  501.   return object;
  502. }
  503.  
  504. /* a buffer which is used to hold output being built by prin1-to-string */
  505. Lisp_Object Vprin1_to_string_buffer;
  506.  
  507. DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 2, 0,
  508.   "Return a string containing the printed representation of OBJECT,\n\
  509. any Lisp object.  Quoting characters are used when needed to make output\n\
  510. that `read' can handle, whenever this is possible, unless the optional\n\
  511. second argument NOESCAPE is non-nil.")
  512.   (object, noescape)
  513.      Lisp_Object object, noescape;
  514. {
  515.   /* This function can GC */
  516.   Lisp_Object old = Fcurrent_buffer ();
  517.   struct buffer *out = XBUFFER (Vprin1_to_string_buffer);
  518.   Lisp_Object stream = Qnil;
  519.   struct gcpro gcpro1, gcpro2, gcpro3;
  520.  
  521.   GCPRO3 (object, old, stream);
  522.   stream = print_prepare (Vprin1_to_string_buffer);
  523.   set_buffer_internal (out);
  524.   Ferase_buffer (Fcurrent_buffer ());
  525.   print_depth = 0;
  526.   print_internal (object, stream, NILP (noescape));
  527.   print_finish (stream);
  528.   stream = Qnil;                /* No GC surprises! */
  529.   object = make_string_from_buffer (out, 
  530.                     BUF_BEG (out),
  531.                     BUF_Z (out) - 1);
  532.   Ferase_buffer (Fcurrent_buffer ());
  533.   Fset_buffer (old);
  534.   UNGCPRO;
  535.   return (object);
  536. }
  537.  
  538. DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0,
  539.   "Output the printed representation of OBJECT, any Lisp object.\n\
  540. No quoting characters are used; no delimiters are printed around\n\
  541. the contents of strings.\n\
  542. Output stream is STREAM, or value of standard-output (which see).")
  543.   (obj, stream)
  544.      Lisp_Object obj, stream;
  545. {
  546.   /* This function can GC */
  547.   Lisp_Object the_stream = Qnil;
  548.   struct gcpro gcpro1, gcpro2, gcpro3;
  549.  
  550.   GCPRO3 (obj, stream, the_stream);
  551.   the_stream = print_prepare (stream);
  552.   print_depth = 0;
  553.   print_internal (obj, the_stream, 0);
  554.   print_finish (the_stream);
  555.   UNGCPRO;
  556.   return (obj);
  557. }
  558.  
  559. DEFUN ("print", Fprint, Sprint, 1, 2, 0,
  560.   "Output the printed representation of OBJECT, with newlines around it.\n\
  561. Quoting characters are printed when needed to make output that `read'\n\
  562. can handle, whenever this is possible.\n\
  563. Output stream is STREAM, or value of `standard-output' (which see).")
  564.   (obj, stream)
  565.      Lisp_Object obj, stream;
  566. {
  567.   /* This function can GC */
  568.   Lisp_Object the_stream = Qnil;
  569.   struct gcpro gcpro1, gcpro2, gcpro3;
  570.  
  571.   GCPRO3 (obj, stream, the_stream);
  572.   the_stream = print_prepare (stream);
  573.   print_depth = 0;
  574.   write_char_internal ("\n", the_stream);
  575.   print_internal (obj, the_stream, 1);
  576.   write_char_internal ("\n", the_stream);
  577.   print_finish (the_stream);
  578.   UNGCPRO;
  579.   return obj;
  580. }
  581.  
  582. #ifdef LISP_FLOAT_TYPE
  583.  
  584. Lisp_Object Vfloat_output_format;
  585. Lisp_Object Qfloat_output_format;
  586.  
  587. void
  588. float_to_string (char *buf, double data)
  589. /*
  590.  * This buffer should be at least as large as the max string size of the
  591.  * largest float, printed in the biggest notation.  This is undoubtably
  592.  * 20d float_output_format, with the negative of the C-constant "HUGE"
  593.  * from <math.h>.
  594.  * 
  595.  * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
  596.  * 
  597.  * I assume that IEEE-754 format numbers can take 329 bytes for the worst
  598.  * case of -1e307 in 20d float_output_format. What is one to do (short of
  599.  * re-writing _doprnt to be more sane)?
  600.  *             -wsr
  601.  */
  602. {
  603.   Bufbyte *cp, c;
  604.   int width;
  605.       
  606.   if (NILP (Vfloat_output_format)
  607.       || !STRINGP (Vfloat_output_format))
  608.   lose:
  609.     sprintf (buf, "%.16g", data);
  610.   else            /* oink oink */
  611.     {
  612.       /* Check that the spec we have is fully valid.
  613.      This means not only valid for printf,
  614.      but meant for floats, and reasonable.  */
  615.       cp = string_data (XSTRING (Vfloat_output_format));
  616.  
  617.       if (cp[0] != '%')
  618.     goto lose;
  619.       if (cp[1] != '.')
  620.     goto lose;
  621.  
  622.       cp += 2;
  623.       for (width = 0; (c = *cp, isdigit (c)); cp++)
  624.     {
  625.       width *= 10;
  626.       width += c - '0';
  627.     }
  628.  
  629.       if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G') 
  630.     goto lose;
  631.  
  632.       if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG)
  633.     goto lose;
  634.  
  635.       if (cp[1] != 0)
  636.     goto lose;
  637.  
  638.       sprintf (buf, (char *) string_data (XSTRING (Vfloat_output_format)),
  639.            data);
  640.     }
  641.  
  642.   /* added by jwz: don't allow "1.0" to print as "1"; that destroys
  643.      the read-equivalence of lisp objects.  (* x 1) and (* x 1.0) do
  644.      not do the same thing, so it's important that the printed
  645.      representation of that form not be corrupted by the printer.
  646.    */
  647.   {
  648.     Bufbyte *s = (Bufbyte *) buf; /* don't use signed chars here!
  649.                      isdigit() can't hack them! */
  650.     if (*s == '-') s++;
  651.     for (; *s; s++)
  652.       /* if there's a non-digit, then there is a decimal point, or
  653.      it's in exponential notation, both of which are ok. */
  654.       if (!isdigit (*s))
  655.     goto DONE_LABEL;
  656.     /* otherwise, we need to hack it. */
  657.     *s++ = '.';
  658.     *s++ = '0';
  659.     *s = 0;
  660.   }
  661.  DONE_LABEL:
  662.  
  663.   /* Some machines print "0.4" as ".4".  I don't like that. */
  664.   if (buf [0] == '.' || (buf [0] == '-' && buf [1] == '.'))
  665.     {
  666.       int i;
  667.       for (i = strlen (buf) + 1; i >= 0; i--)
  668.     buf [i+1] = buf [i];
  669.       buf [(buf [0] == '-' ? 1 : 0)] = '0';
  670.     }
  671. }
  672. #endif /* LISP_FLOAT_TYPE */
  673.  
  674. static void
  675. print_vector_internal (CONST char *start, CONST char *end,
  676.                        Lisp_Object obj, 
  677.                        Lisp_Object printcharfun, int escapeflag)
  678. {
  679.   /* This function can GC */
  680.   int i;
  681.   int len = vector_length (XVECTOR (obj));
  682.   int last = len;
  683.   struct gcpro gcpro1, gcpro2;
  684.   GCPRO2 (obj, printcharfun);
  685.  
  686.   if (INTP (Vprint_length))
  687.     {
  688.       int max = XINT (Vprint_length);
  689.       if (max < len) last = max;
  690.     }
  691.  
  692.   write_c_string (start, printcharfun);
  693.   for (i = 0; i < last; i++)
  694.     {
  695.       Lisp_Object elt = vector_data (XVECTOR (obj))[i];
  696.       if (i != 0) write_char_internal (" ", printcharfun);
  697.       print_internal (elt, printcharfun, escapeflag);
  698.     }
  699.   UNGCPRO;
  700.   if (last != len)
  701.     write_c_string (" ...", printcharfun);
  702.   write_c_string (end, printcharfun);
  703. }
  704.  
  705. static void
  706. default_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
  707.             int escapeflag)
  708. {
  709.   struct lcrecord_header *header =
  710.     (struct lcrecord_header *) XPNTR (obj);
  711.   char buf[200];
  712.  
  713.   if (print_readably)
  714.     error ("printing unreadable object #<%s 0x%x>",
  715.        header->lheader.implementation->name, header->uid);
  716.  
  717.   sprintf (buf, "#<%s 0x%x>", header->lheader.implementation->name,
  718.        header->uid);
  719.   write_c_string (buf, printcharfun);
  720. }
  721.  
  722. void
  723. print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
  724. {
  725.   /* This function can GC */
  726.   char buf[256];
  727.  
  728.   QUIT;
  729.  
  730.   /* Emacs won't print whilst GCing, but an external debugger might */
  731.   if (gc_in_progress) return;
  732.  
  733. #ifdef I18N3
  734.   /* #### Both input and output streams should have a flag associated
  735.      with them indicating whether output to that stream, or strings
  736.      read from the stream, get translated using Fgettext().  Such a
  737.      stream is called a "translating stream".  For the minibuffer and
  738.      external-debugging-output this is always true on output, and
  739.      with-output-to-temp-buffer sets the flag to true for the buffer
  740.      it creates.  This flag should also be user-settable.  Perhaps it
  741.      should be split up into two flags, one for input and one for
  742.      output. */
  743. #endif
  744.  
  745.   print_depth++;
  746.  
  747.   if (print_depth > 200)
  748.     error ("Apparently circular structure being printed");
  749.  
  750.   switch (XTYPE (obj))
  751.     {
  752.     case Lisp_Int:
  753.       {
  754.     sprintf (buf, "%d", XINT (obj));
  755.     write_c_string (buf, printcharfun);
  756.     break;
  757.       }
  758.  
  759.     case Lisp_String:
  760.       {
  761.     Bytecount size = string_length (XSTRING (obj));
  762.     struct gcpro gcpro1, gcpro2;
  763.     int max = size;
  764.     GCPRO2 (obj, printcharfun);
  765.  
  766.     if (INTP (Vprint_string_length) &&
  767.         XINT (Vprint_string_length) < max)
  768.       max = XINT (Vprint_string_length);
  769.     if (max < 0)
  770.       max = 0;
  771.  
  772.     if (!escapeflag)
  773.       {
  774.         /* This deals with GC-relocation */
  775.         output_string (printcharfun, 0, obj, 0, max);
  776.         if (max < size)
  777.           write_c_string (" ...", printcharfun);
  778.       }
  779.     else
  780.       {
  781.         Bytecount i;
  782.         struct Lisp_String *s = XSTRING (obj);
  783.         Bytecount last = 0;
  784.  
  785.         write_char_internal ("\"", printcharfun);
  786.         for (i = 0; i < max; i++)
  787.           {
  788.         Bufbyte ch = string_byte (s, i);
  789.         if (ch == '\"' || ch == '\\' 
  790.             || (ch == '\n' && print_escape_newlines))
  791.           {
  792.             if (i > last)
  793.               {
  794.             output_string (printcharfun, 0, obj, last,
  795.                        i - last);
  796.               }
  797.             if (ch == '\n')
  798.               {
  799.             write_c_string ("\\n", printcharfun);
  800.               }
  801.             else
  802.               {
  803.             write_char_internal ("\\", printcharfun);
  804.             /* This is correct for Mule because the
  805.                character is either \ or " */
  806.             write_char_internal ((char *) (string_data (s) + i),
  807.                          printcharfun);
  808.               }
  809.             last = i + 1;
  810.           }
  811.           }
  812.         if (max > last)
  813.           {
  814.         output_string (printcharfun, 0, obj, last,
  815.                    max - last);
  816.           }
  817.         if (max < size)
  818.           write_c_string (" ...", printcharfun);
  819.         write_char_internal ("\"", printcharfun);
  820.       }
  821.     UNGCPRO;
  822.     break;
  823.       }
  824.  
  825.     case Lisp_Cons:
  826.       {
  827.     struct gcpro gcpro1, gcpro2;
  828.  
  829.     /* If deeper than spec'd depth, print placeholder.  */
  830.     if (INTP (Vprint_level)
  831.         && print_depth > XINT (Vprint_level))
  832.       {
  833.         write_c_string ("...", printcharfun);
  834.         break;
  835.       }
  836.  
  837.     /* If print_readably is on, print (quote -foo-) as '-foo-
  838.        (Yeah, this should really be what print-pretty does, but we
  839.        don't have the rest of a pretty printer, and this actually
  840.        has non-negligible impact on size/speed of .elc files.)
  841.      */
  842.     if (print_readably &&
  843.         EQ (XCAR (obj), Qquote) &&
  844.         CONSP (XCDR (obj)) &&
  845.         NILP (XCDR (XCDR (obj))))
  846.       {
  847.         obj = XCAR (XCDR (obj));
  848.         GCPRO2 (obj, printcharfun);
  849.         write_char_internal ("'", printcharfun);
  850.         UNGCPRO;
  851.         print_internal (obj, printcharfun, escapeflag);
  852.         break;
  853.       }
  854.  
  855.     GCPRO2 (obj, printcharfun);
  856.     write_char_internal ("(", printcharfun);
  857.     {
  858.       int i = 0;
  859.       int max = 0;
  860.  
  861.       if (INTP (Vprint_length))
  862.         max = XINT (Vprint_length);
  863.       while (CONSP (obj))
  864.         {
  865.           if (i++)
  866.         write_char_internal (" ", printcharfun);
  867.           if (max && i > max)
  868.         {
  869.           write_c_string ("...", printcharfun);
  870.           break;
  871.         }
  872.           print_internal (Fcar (obj), printcharfun,
  873.                   escapeflag);
  874.           obj = Fcdr (obj);
  875.         }
  876.     }
  877.     if (!NILP (obj) && !CONSP (obj))
  878.       {
  879.         write_c_string (" . ", printcharfun);
  880.         print_internal (obj, printcharfun, escapeflag);
  881.       }
  882.     UNGCPRO;
  883.     write_char_internal (")", printcharfun);
  884.     break;
  885.       }
  886.  
  887. #ifndef LRECORD_VECTOR
  888.     case Lisp_Vector:
  889.       {
  890.     /* If deeper than spec'd depth, print placeholder.  */
  891.     if (INTP (Vprint_level)
  892.         && print_depth > XINT (Vprint_level))
  893.       {
  894.         write_c_string ("...", printcharfun);
  895.         break;
  896.       }
  897.  
  898.     /* God intended that this be #(...), you know. */
  899.     print_vector_internal ("[", "]", obj, printcharfun, escapeflag);
  900.     break;
  901.       }
  902. #endif /* !LRECORD_VECTOR */
  903.  
  904. #ifndef LRECORD_SYMBOL
  905.     case Lisp_Symbol:
  906.       {
  907.         print_symbol (obj, printcharfun, escapeflag);
  908.         break;
  909.       }
  910. #endif /* !LRECORD_SYMBOL */
  911.  
  912.     case Lisp_Record:
  913.       {
  914.     struct lrecord_header *lheader = XRECORD_LHEADER (obj);
  915.     struct gcpro gcpro1, gcpro2;
  916.  
  917.     GCPRO2 (obj, printcharfun);
  918.     if (lheader->implementation->printer)
  919.       ((lheader->implementation->printer)
  920.        (obj, printcharfun, escapeflag));
  921.     else
  922.       default_object_printer (obj, printcharfun, escapeflag);
  923.     UNGCPRO;
  924.     break;
  925.       }
  926.  
  927.     default:
  928.       {
  929.     /* We're in trouble if this happens!
  930.        Probably should just abort () */
  931.     if (print_readably)
  932.       error ("printing illegal data type #o%03o",
  933.          (int) XTYPE (obj));
  934.     write_c_string ("#<EMACS BUG: ILLEGAL DATATYPE ",
  935.             printcharfun);
  936.     sprintf (buf, "(#o%3o)", (int) XTYPE (obj));
  937.     write_c_string (buf, printcharfun);
  938.     write_c_string
  939.       (" Save your buffers immediately and please report this bug>",
  940.        printcharfun);
  941.     break;
  942.       }
  943.     }
  944.  
  945.   print_depth--;
  946. }
  947.  
  948. static void
  949. print_bytecode_internal (CONST char *start, CONST char *end,
  950.                          Lisp_Object obj, 
  951.                          Lisp_Object printcharfun, int escapeflag)
  952. {
  953.   /* This function can GC */
  954.   struct Lisp_Bytecode *b = XBYTECODE (obj); /* GC doesn't relocate */
  955.   int docp = b->flags.documentationp;
  956.   int intp = b->flags.interactivep;
  957.   struct gcpro gcpro1, gcpro2;
  958.   char buf[100];
  959.   GCPRO2 (obj, printcharfun);
  960.  
  961.   write_c_string (start, printcharfun);
  962.   /* COMPILED_ARGLIST = 0 */
  963.   print_internal (b->arglist, printcharfun, escapeflag);
  964.   /* COMPILED_BYTECODE = 1 */
  965.   write_char_internal (" ", printcharfun);
  966.   print_internal (b->bytecodes, printcharfun, escapeflag);
  967.   /* COMPILED_CONSTANTS = 2 */
  968.   write_char_internal (" ", printcharfun);
  969.   print_internal (b->constants, printcharfun, escapeflag);
  970.   /* COMPILED_STACK_DEPTH = 3 */
  971.   sprintf (buf, " %d", b->maxdepth);
  972.   write_c_string (buf, printcharfun);
  973.   /* COMPILED_DOC_STRING = 4 */
  974.   if (docp || intp)
  975.     {
  976.       write_char_internal (" ", printcharfun);
  977.       print_internal (bytecode_documentation (b), printcharfun,
  978.               escapeflag);
  979.     }
  980.   /* COMPILED_INTERACTIVE = 5 */
  981.   if (intp)
  982.     {
  983.       write_char_internal (" ", printcharfun);
  984.       print_internal (bytecode_interactive (b), printcharfun,
  985.               escapeflag);
  986.     }
  987.   UNGCPRO;
  988.   write_c_string (end, printcharfun);
  989. }
  990.  
  991. void
  992. print_bytecode (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
  993. {
  994.   /* This function can GC */
  995.   print_bytecode_internal (((print_readably) ? "#[" : "#<byte-code "),
  996.                            ((print_readably) ? "]" : ">"),
  997.                            obj, printcharfun, escapeflag);
  998. }
  999.  
  1000. #ifdef LISP_FLOAT_TYPE
  1001. void
  1002. print_float (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
  1003. {
  1004.   char pigbuf[350];    /* see comments in float_to_string */
  1005.  
  1006.   float_to_string (pigbuf, float_data (XFLOAT (obj)));
  1007.   write_c_string (pigbuf, printcharfun);
  1008. }
  1009. #endif /* LISP_FLOAT_TYPE */
  1010.  
  1011. void
  1012. print_symbol (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
  1013. {
  1014.   /* This function can GC */
  1015.   /* #### Bug!! (intern "") isn't printed in some distinguished way */
  1016.   /* ####  (the reader also loses on it) */
  1017.   struct Lisp_String *name = XSYMBOL (obj)->name;
  1018.   Bytecount size = string_length (name);
  1019.   struct gcpro gcpro1, gcpro2;
  1020.  
  1021.   if (!escapeflag)
  1022.     {
  1023.       /* This deals with GC-relocation */
  1024.       Lisp_Object nameobj;
  1025.       XSETSTRING (nameobj, name);
  1026.       output_string (printcharfun, 0, nameobj, 0, size);
  1027.       return;
  1028.     }
  1029.   GCPRO2 (obj, printcharfun);
  1030.  
  1031.   if (print_gensym) 
  1032.     {
  1033.       Lisp_Object tem = oblookup (Vobarray, string_data (name), size);
  1034.       if (!EQ (tem, obj))
  1035.     /* (read) would return a new symbol with the same name.
  1036.        This isn't quite correct, because that symbol might not
  1037.        really be uninterned (it might be interned in some other
  1038.        obarray) but there's no way to win in that case without
  1039.        implementing a real package system.
  1040.        */
  1041.     write_c_string ("#:", printcharfun);
  1042.     }
  1043.  
  1044.   /* Does it look like an integer or a float? */
  1045.   {
  1046.     Bufbyte *data = string_data (name);
  1047.     Bytecount confusing = 0;
  1048.  
  1049.     if (size == 0)
  1050.       goto not_yet_confused;    /* Really confusing */
  1051.     else if (isdigit (data[0]))
  1052.       confusing = 0;
  1053.     else if (size == 1)
  1054.       goto not_yet_confused;
  1055.     else if (data[0] == '-' || data[0] == '+')
  1056.       confusing = 1;
  1057.     else
  1058.       goto not_yet_confused;
  1059.  
  1060.     for (; confusing < size; confusing++)
  1061.       { 
  1062.         if (!isdigit (data[confusing]))
  1063.           {
  1064.             confusing = 0;
  1065.             break;
  1066.           }
  1067.       }
  1068.   not_yet_confused:
  1069.  
  1070. #ifdef LISP_FLOAT_TYPE
  1071.     if (!confusing)
  1072.       confusing = isfloat_string ((char *) data);
  1073. #endif
  1074.     if (confusing)
  1075.       write_char_internal ("\\", printcharfun);
  1076.   }
  1077.  
  1078.   {
  1079.     Lisp_Object nameobj;
  1080.     Bytecount i;
  1081.     Bytecount last = 0;
  1082.         
  1083.     XSETSTRING (nameobj, name);
  1084.     for (i = 0; i < size; i++)
  1085.       {
  1086.     Bufbyte c = string_byte (name, i);
  1087.  
  1088.     if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' ||
  1089.         c == '(' || c == ')' || c == ',' || c =='.' || c == '`' ||
  1090.         c == '[' || c == ']' || c == '?' || c <= 040)
  1091.       {
  1092.         if (i > last)
  1093.           {
  1094.         output_string (printcharfun, 0, nameobj, last,
  1095.                    i - last);
  1096.           }
  1097.         write_char_internal ("\\", printcharfun);
  1098.         last = i;
  1099.       }
  1100.       }
  1101.     output_string (printcharfun, 0, nameobj, last, size - last);
  1102.   }
  1103.   UNGCPRO;
  1104. }
  1105.  
  1106.  
  1107. int alternate_do_pointer;
  1108. char alternate_do_string[5000];
  1109.  
  1110. DEFUN ("alternate-debugging-output", Falternate_debugging_output,
  1111.        Salternate_debugging_output, 1, 1, 0,
  1112.   "Append CHARACTER to the array `alternate_do_string'.\n\
  1113. This can be used in place of `external-debugging-output' as a function\n\
  1114. to be passed to `print'.  Before calling `print', set `alternate_do_pointer'\n\
  1115. to 0.\n")
  1116.   (character)
  1117.      Lisp_Object character;
  1118. {
  1119.   Bufbyte str[MAX_EMCHAR_LEN];
  1120.   Bytecount len;
  1121.   int extlen;
  1122.   char *extptr;
  1123.  
  1124.   CHECK_COERCE_CHAR (character, 0);
  1125.   len = emchar_to_charptr (XINT (character), str);
  1126.   extptr = charptr_to_external (str, len, &extlen);
  1127.   memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen);
  1128.   alternate_do_pointer += extlen;
  1129.   alternate_do_string[alternate_do_pointer] = 0;
  1130.   return character;
  1131. }
  1132.  
  1133. DEFUN ("external-debugging-output", Fexternal_debugging_output,
  1134.        Sexternal_debugging_output, 1, 2, 0,
  1135.   "Write CHAR-OR-STRING to stderr or stdout.\n\
  1136. If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write\n\
  1137. to stderr.  You can use this function to write directly to the terminal.\n\
  1138. This function can be used as the STREAM argument of Fprint() or the like.\n\
  1139. \n\
  1140. If you have opened a termscript file (using `open-termscript'), then\n\
  1141. the output also will be logged to this file.")
  1142.   (char_or_string, stdout_p)
  1143.      Lisp_Object char_or_string, stdout_p;
  1144. {
  1145.   if (STRINGP (char_or_string))
  1146.     write_string_to_stdio_stream (!NILP (stdout_p) ? stdout : stderr,
  1147.                   string_data (XSTRING (char_or_string)),
  1148.                   0, string_length (XSTRING (char_or_string)));
  1149.   else
  1150.     {
  1151.       Bufbyte str[MAX_EMCHAR_LEN];
  1152.       Bytecount len;
  1153.  
  1154.       CHECK_COERCE_CHAR (char_or_string, 0);
  1155.       len = emchar_to_charptr (XINT (char_or_string), str);
  1156.       write_string_to_stdio_stream (!NILP (stdout_p) ? stdout : stderr,
  1157.                     str, 0, len);
  1158.     }
  1159.  
  1160.   return char_or_string;
  1161. }
  1162.  
  1163. DEFUN ("open-termscript", Fopen_termscript, Sopen_termscript,
  1164.   1, 1, "FOpen termscript file: ",
  1165.   "Start writing all terminal output to FILE as well as the terminal.\n\
  1166. FILE = nil means just close any termscript file currently open.")
  1167.   (file)
  1168.      Lisp_Object file;
  1169. {
  1170.   /* This function can GC */
  1171.   if (termscript != 0)
  1172.     fclose (termscript);
  1173.   termscript = 0;
  1174.  
  1175.   if (! NILP (file))
  1176.     {
  1177.       file = Fexpand_file_name (file, Qnil);
  1178.       termscript = fopen ((char *) string_data (XSTRING (file)), "w");
  1179.       if (termscript == 0)
  1180.     report_file_error ("Opening termscript", Fcons (file, Qnil));
  1181.     }
  1182.   return Qnil;
  1183. }
  1184.  
  1185. #if 1
  1186. /* Debugging kludge -- unbuffered */
  1187. static int debug_print_length = 50;
  1188. static int debug_print_level = 15;
  1189. Lisp_Object debug_temp;
  1190. void debug_print (Lisp_Object debug_print_obj);
  1191. void
  1192. debug_print (Lisp_Object debug_print_obj)
  1193. {
  1194.   /* This function can GC */
  1195.   int old_print_readably = print_readably;
  1196.   int old_print_depth = print_depth;
  1197.   Lisp_Object old_print_length = Vprint_length;
  1198.   Lisp_Object old_print_level = Vprint_level;
  1199.   Lisp_Object old_inhibit_quit = Vinhibit_quit;
  1200.   struct gcpro gcpro1, gcpro2, gcpro3;
  1201.   GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
  1202.  
  1203.   if (gc_in_progress)
  1204.     stderr_out ("** gc-in-progress!  Bad idea to print anything! **\n");
  1205.  
  1206.   print_depth = 0;
  1207.   print_readably = 0;
  1208.   print_unbuffered++;
  1209.   /* Could use unwind-protect, but why bother? */
  1210.   if (debug_print_length > 0)
  1211.     Vprint_length = make_number (debug_print_length);
  1212.   if (debug_print_level > 0)
  1213.     Vprint_level = make_number (debug_print_level);
  1214.   print_internal (debug_print_obj, Qexternal_debugging_output, 1);
  1215.   stderr_out ("\n");
  1216.   fflush (stderr);
  1217.   Vinhibit_quit = old_inhibit_quit;
  1218.   Vprint_level = old_print_level;
  1219.   Vprint_length = old_print_length;
  1220.   print_depth = old_print_depth;
  1221.   print_readably = old_print_readably;
  1222.   print_unbuffered--;
  1223.   UNGCPRO;
  1224. }
  1225.  
  1226. /* Debugging kludge -- unbuffered */
  1227. void debug_backtrace (void);
  1228. void
  1229. debug_backtrace (void)
  1230. {
  1231.   /* This function can GC */
  1232.   int old_print_readably = print_readably;
  1233.   int old_print_depth = print_depth;
  1234.   Lisp_Object old_print_length = Vprint_length;
  1235.   Lisp_Object old_print_level = Vprint_level;
  1236.   Lisp_Object old_inhibit_quit = Vinhibit_quit;
  1237.   struct gcpro gcpro1, gcpro2, gcpro3;
  1238.   GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
  1239.  
  1240.   if (gc_in_progress)
  1241.     stderr_out ("** gc-in-progress!  Bad idea to print anything! **\n");
  1242.  
  1243.   print_depth = 0;
  1244.   print_readably = 0;
  1245.   print_unbuffered++;
  1246.   /* Could use unwind-protect, but why bother? */
  1247.   if (debug_print_length > 0)
  1248.     Vprint_length = make_number (debug_print_length);
  1249.   if (debug_print_level > 0)
  1250.     Vprint_level = make_number (debug_print_level);
  1251.   Fbacktrace (Qexternal_debugging_output, Qt);
  1252.   stderr_out ("\n");
  1253.   fflush (stderr);
  1254.   Vinhibit_quit = old_inhibit_quit;
  1255.   Vprint_level = old_print_level;
  1256.   Vprint_length = old_print_length;
  1257.   print_depth = old_print_depth;
  1258.   print_readably = old_print_readably;
  1259.   print_unbuffered--;
  1260.   UNGCPRO;
  1261. }
  1262.  
  1263. #endif /* debugging kludge */
  1264.  
  1265.  
  1266. void
  1267. syms_of_print (void)
  1268. {
  1269.   defsymbol (&Qprint_escape_newlines, "print-escape-newlines");
  1270.   defsymbol (&Qprint_readably, "print-readably");
  1271.  
  1272.   defsymbol (&Qstandard_output, "standard-output");
  1273.  
  1274. #ifdef LISP_FLOAT_TYPE
  1275.   defsymbol (&Qfloat_output_format, "float-output-format");
  1276. #endif
  1277.  
  1278.   defsymbol (&Qprint_length, "print-length");
  1279.  
  1280.   defsymbol (&Qprint_string_length, "print-string-length");
  1281.   defsubr (&Sprin1);
  1282.   defsubr (&Sprin1_to_string);
  1283.   defsubr (&Sprinc);
  1284.   defsubr (&Sprint);
  1285.   defsubr (&Sterpri);
  1286.   defsubr (&Swrite_char);
  1287.   defsubr (&Salternate_debugging_output);
  1288.   defsymbol (&Qalternate_debugging_output, "alternate-debugging-output");
  1289.   defsubr (&Sexternal_debugging_output);
  1290.   defsubr (&Sopen_termscript);
  1291.   defsymbol (&Qexternal_debugging_output, "external-debugging-output");
  1292. #ifndef standalone
  1293.   defsubr (&Swith_output_to_temp_buffer);
  1294. #endif /* not standalone */
  1295. }
  1296.  
  1297. void
  1298. vars_of_print (void)
  1299. {
  1300.   alternate_do_pointer = 0;
  1301.  
  1302.   DEFVAR_LISP ("standard-output", &Vstandard_output,
  1303.     "Output stream `print' uses by default for outputting a character.\n\
  1304. This may be any function of one argument.\n\
  1305. It may also be a buffer (output is inserted before point)\n\
  1306. or a marker (output is inserted and the marker is advanced)\n\
  1307. or the symbol t (output appears in the minibuffer line).");
  1308.   Vstandard_output = Qt;
  1309.  
  1310. #ifdef LISP_FLOAT_TYPE
  1311.   DEFVAR_LISP ("float-output-format", &Vfloat_output_format,
  1312.     "The format descriptor string that lisp uses to print floats.\n\
  1313. This is a %-spec like those accepted by `printf' in C,\n\
  1314. but with some restrictions.  It must start with the two characters `%.'.\n\
  1315. After that comes an integer precision specification,\n\
  1316. and then a letter which controls the format.\n\
  1317. The letters allowed are `e', `f' and `g'.\n\
  1318. Use `e' for exponential notation \"DIG.DIGITSeEXPT\"\n\
  1319. Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\
  1320. Use `g' to choose the shorter of those two formats for the number at hand.\n\
  1321. The precision in any of these cases is the number of digits following\n\
  1322. the decimal point.  With `f', a precision of 0 means to omit the\n\
  1323. decimal point.  0 is not allowed with `f' or `g'.\n\n\
  1324. A value of nil means to use `%.16g'.\n\
  1325. \n\
  1326. Regardless of the value of `float-output-format', a floating point number\n\
  1327. will never be printed in such a way that it is ambiguous with an integer;\n\
  1328. that is, a floating-point number will always be printed with a decimal\n\
  1329. point and/or an exponent, even if the digits following the decimal point\n\
  1330. are all zero.  This is to preserve read-equivalence.");
  1331.   Vfloat_output_format = Qnil;
  1332. #endif /* LISP_FLOAT_TYPE */
  1333.  
  1334.   DEFVAR_LISP ("print-length", &Vprint_length,
  1335.     "Maximum length of list or vector to print before abbreviating.\n\
  1336. A value of nil means no limit.");
  1337.   Vprint_length = Qnil;
  1338.  
  1339.   DEFVAR_LISP ("print-string-length", &Vprint_string_length,
  1340.     "Maximum length of string to print before abbreviating.\n\
  1341. A value of nil means no limit.");
  1342.   Vprint_string_length = Qnil;
  1343.  
  1344.   DEFVAR_LISP ("print-level", &Vprint_level,
  1345.     "Maximum depth of list nesting to print before abbreviating.\n\
  1346. A value of nil means no limit.");
  1347.   Vprint_level = Qnil;
  1348.  
  1349.   DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines,
  1350.     "Non-nil means print newlines in strings as backslash-n.");
  1351.   print_escape_newlines = 0;
  1352.  
  1353.   DEFVAR_BOOL ("print-readably", &print_readably,
  1354.     "If non-nil, then all objects will be printed in a readable form.\n\
  1355. If an object has no readable representation, then an error is signalled.\n\
  1356. When print-readably is true, compiled-function objects will be written in\n\
  1357.  #[...] form instead of in #<byte-code [...]> form, and two-element lists\n\
  1358.  of the form (quote object) will be written as the equivalent 'object.\n\
  1359. Do not SET this variable; bind it instead.");
  1360.   print_readably = 0;
  1361.  
  1362.   DEFVAR_BOOL ("print-gensym", &print_gensym,
  1363.     "If non-nil, then uninterned symbols will be printed specially.\n\
  1364. Uninterned symbols are those which are not present in `obarray', that is,\n\
  1365. those which were made with `make-symbol' or by calling `intern' with a\n\
  1366. second argument.\n\
  1367. \n\
  1368. When print-gensym is true, such symbols will be preceeded by \"#:\", which\n\
  1369. causes the reader to create a new symbol instead of interning and returning\n\
  1370. an existing one.  Beware: the #: syntax creates a new symbol each time it is\n\
  1371. seen, so if you print an object which contains two pointers to the same\n\
  1372. uninterned symbol, `read' will not duplicate that structure.\n\
  1373. \n\
  1374. Also, since emacs has no real notion of packages, there is no way for the\n\
  1375. printer to distinguish between symbols interned in no obarray, and symbols\n\
  1376. interned in an alternate obarray.");
  1377.   print_gensym = 0;
  1378.  
  1379.   DEFVAR_LISP ("print-message-label", &Vprint_message_label,
  1380.     "Label for minibuffer messages created with `print'.  This should\n\
  1381. generally be bound with `let' rather than set.  (See `display-message'.)");
  1382.   Vprint_message_label = Qprint;
  1383.  
  1384.   /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
  1385.   staticpro (&Vprin1_to_string_buffer);
  1386. }
  1387.